package cn.myjerry.test.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 测试ResultSet的用法
 * @author Jerry
 *
 */
public class Demo03 {
	// JDBC 驱动名及数据库 URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
    static final String DB_URL = "jdbc:mysql://localhost:3306/testjdbc?useSSL=true&useUnicode=true&characterEncoding=utf8";
    
    // 数据库的用户名与密码，需要根据自己的设置
    static final String USER = "root";
    static final String PASS = "Jerry1912317";
	
	public static void main(String[] args) throws Exception {
		// 加载驱动类
		Class.forName(JDBC_DRIVER);
		// 建立连接
		Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

		//String sql = "SELECT * FROM User WHERE Id >= ?";
		String sql = "SELECT * FROM `User` INNER JOIN `Order`";
		PreparedStatement ps = conn.prepareStatement(sql);
		//ps.setInt(1, 10);
		ResultSet res = ps.executeQuery();
		while(res.next()) {
			System.out.println(res.getInt(1) + "==>" + res.getString(2) + "==>" + res.getString(3) + "==>" + res.getString(4) + "==>"
					+ res.getInt(5) + "==>" + res.getInt(6) + "==>" +res.getInt(7));
		}
		if(res != null) {
			res.close();
		}
		if(ps != null) {
			ps.close();
		}
		if(conn != null) {
			conn.close();
		}
	}
}
